package com.sfh.cpc.mass.model;

import com.sfh.cpc.com.entity.EMass;
import com.sfh.cpc.com.entity.RspBase;
import com.sfh.cpc.com.entity.RspPage;
import com.sfh.cpc.com.req.ReqMassDel;
import com.sfh.cpc.com.req.ReqMassSearch;
import com.sfh.cpc.com.req.ReqPageMass;
import com.sfh.cpc.com.req.ReqPageUserMass;
import com.sfh.lib.exception.HandleException;
import com.sfh.lib.mvvm.service.BaseViewModel;
import com.sfh.lib.rx.IResult;

/**
 * 功能描述: TODO
 *
 * @author SunFeihu 孙飞虎
 * @date 2018/8/27
 */
public class MassModel extends BaseViewModel implements IResult<RspBase<RspPage<EMass>>> {
    public void queryMass(int nowPage,String content){

    }
    public void delMass(long massID){
        this.execute(false,new ReqMassDel(massID), new IResult<RspBase>() {
            @Override
            public void onSuccess(RspBase rspBase) throws Exception {
                if (rspBase.success()){
                    setValue("onRefreshUI");
                }else{
                    showToast(rspBase.getMsg());
                }
            }

            @Override
            public void onFail(HandleException e) {
                showToast(e.getMsg());
            }
        });
    }
    public void pageUserMass(int nowPage) {
        this.execute(new ReqPageUserMass(nowPage),this);
    }

    /***
     * 名称模糊查询
     * @param nowPage
     * @param title
     */
    public void pageSearchMass(int nowPage,String title) {

        ReqMassSearch req = new ReqMassSearch();
        req.setNowPage(nowPage);
        req.setContent(title);
        this.execute(req, this);
    }

    public void pageMass(int nowPage,String massType) {
        this.execute(new ReqPageMass(nowPage,massType), this);
    }
    @Override
    public void onFail(HandleException e) {
        setValue("onPageSuccess");
    }

    @Override
    public void onSuccess(RspBase<RspPage<EMass>> data) throws Exception {
        if (data.success()) {
            setValue("onPageSuccess", data.getData());
        } else {
            setValue("onPageSuccess");
        }
    }
}
